package conditions;

import impsoft.scripting.ibot.builtin.itemrec.IdentifiedItem;
import impsoft.scripting.ibot.itemrec.ItemCondition;

public class ItemEqualsAny extends ItemCondition {
	private String[] exactNames;
	private int[] ids;

	public ItemEqualsAny(String... exactNames) {
		this(exactNames, null);
	}

	public ItemEqualsAny(int... ids) {
		this(null, ids);
	}

	public ItemEqualsAny(String[] exactNames, int... ids) {
		this.exactNames = exactNames;
		this.ids = ids;
	}

	public void setItemNames(String... names) {
		exactNames = names;
	}

	public String[] getItemNames() {
		return exactNames;
	}

	public int[] getIDs() {
		return ids;
	}

	@Override
	public boolean valid(IdentifiedItem item) {
		if (item != null) {
			String itemName = item.getItemName();
			if (exactNames != null) {
				for (String name : exactNames) {
					if (name != null && itemName.equalsIgnoreCase(name)) {
						return true;
					}
				}
			}
			int itemId = item.getID();
			if (ids != null) {
				for (int i : ids) {
					if (i == itemId) {
						return true;
					}
				}
			}
		}

		return false;
	}

	@Override
	public boolean validItem(String name) {
		if (exactNames != null) {
			for (String itemName : exactNames) {
				if (name != null && itemName.equalsIgnoreCase(name)) {
					return true;
				}
			}
		}

		return false;
	}

	public boolean validItemContains(String name) {
		if (exactNames != null) {
			for (String itemName : exactNames) {
				if (name != null && itemName.toLowerCase().contains(name)) {
					return true;
				}
			}
		}

		return false;
	}
}